package AddTwoNumbers;

import org.junit.Test;
import static org.junit.Assert.assertEquals;

public class SolutionTest {

    private AddTwoNumbers solution = new AddTwoNumbers(); // 假设 Solution 类包含了 addTwoNumbers 方法

    @Test
    public void testAddTwoNumbers() {
        // 测试数据
        ListNode l1 = new ListNode(2, new ListNode(4, new ListNode(3)));
        ListNode l2 = new ListNode(5, new ListNode(6, new ListNode(4)));

        // 预期结果: 7 -> 0 -> 8
        ListNode expected = new ListNode(7, new ListNode(0, new ListNode(8)));

        // 调用方法
        ListNode result = solution.addTwoNumbers(l1, l2);

        // 检查结果
        assertEquals(expected.val, result.val);
        assertEquals(expected.next.val, result.next.val);
        assertEquals(expected.next.next.val, result.next.next.val);
    }

    @Test
    public void testAddTwoNumbersWithCarry() {
        // 测试数据
        ListNode l1 = new ListNode(9, new ListNode(9, new ListNode(9, new ListNode(9))));
        ListNode l2 = new ListNode(9, new ListNode(9, new ListNode(9)));

        // 预期结果: 8 -> 9 -> 0 -> 0 -> 1
        ListNode expected = new ListNode(8, new ListNode(9, new ListNode(0, new ListNode(0, new ListNode(1)))));

        // 调用方法
        ListNode result = solution.addTwoNumbers(l1, l2);

        // 检查结果
        assertEquals(expected.val, result.val);
        assertEquals(expected.next.val, result.next.val);
        assertEquals(expected.next.next.val, result.next.next.val);
        assertEquals(expected.next.next.next.val, result.next.next.next.val);
        assertEquals(expected.next.next.next.next.val, result.next.next.next.next.val);
    }

    @Test
    public void testAddTwoNumbersOneEmpty() {
        // 测试数据
        ListNode l1 = new ListNode(2, new ListNode(4, new ListNode(3)));
        ListNode l2 = null;

        // 预期结果: 2 -> 4 -> 3
        ListNode expected = new ListNode(2, new ListNode(4, new ListNode(3)));

        // 调用方法
        ListNode result = solution.addTwoNumbers(l1, l2);

        // 检查结果
        assertEquals(expected.val, result.val);
        assertEquals(expected.next.val, result.next.val);
        assertEquals(expected.next.next.val, result.next.next.val);
    }

    @Test
    public void test(){
        // 测试数据
        ListNode l1 = new ListNode(1, new ListNode(2, new ListNode(3, new ListNode(4))));
        ListNode l2 = l1;
        l2 = l2.next;
        System.out.println(l1);
    }
}
